using System;
using System.Collections;

namespace ldapAccountGen
{
    /// <summary>
    /// Summary description for User
    ///
    public class User
    {
        public string uCn;
        public string uSn;
        public string uGn;
        public string uFn;
        public string uPassword;
        public string uHomeDir;
        public string uCollege;
        public string uDn;
        public string uNewDn;
        public string uParentDn;
        public string uEmail;
        public string uMajor;
        public string uArea;

        private Properties.Settings settings = Properties.Settings.Default;

        public User()
        {
        }
        public string cn
        {
            set { uCn = value; }
            get { return uCn; }
        }
        public string sn
        {
            set { uSn = value; }
            get { return uSn; }
        }
        public string gn
        {
            set { uGn = value; }
            get { return uGn; }
        }
        public string fullName
        {
            set { uFn = value; }
            get { return uFn; }
        }
        public string password
        {
            set { uPassword = value; }
            get { return uPassword; }
        }
        public string homeDir
        {
            set { uHomeDir = value; }
            get { return uHomeDir; }
        }
        public string college
        {
            set { uCollege = value; }
            get { return uCollege; }
        }
        public string dn
        {
            set { uDn = value; }
            get { return uDn; }
        }
        public string newDn
        {
            set { uNewDn = value; }
            get { return uNewDn; }
        }
        public string parentDn
        {
            set { uParentDn = value; }
            get { return uParentDn; }
        }
        public string email
        {
            set { uEmail = value; }
            get { return uEmail; }
        }
        public string major
        {
            set { uMajor = value; }
            get { return uMajor; }
        }
        public string area
        {
            set { uArea = value; }
            get { return uArea; }
        }
        public void checkProps(Hashtable ut, string key)
        {
            Colleges colleges = new Colleges();
            string col = colleges.getValue(college);

            string[] row = (string[])ut[key];
            uDn = key;
            
            // Here we check that the account properties match the database properties and 
            // if so set the user object properties.
            // These 4 should always match up otherwise we have a bigger problem.
            if (dn == null || dn == "")
                dn = uDn;
            //uCn = row[0];
            //uSn = row[1];
            //uGn = row[3];
                        
            // These should be checked for sure since legacy accounts may not have them set.
            //if (major == row[2])
            //{
            //    uMajor = row[2];
            //}
            //if (row[9] != null)
            //    uArea = row[9];
            // If a student moves colleges this is what you do.
            if (col != row[4])
            {
                uNewDn = "cn=" + cn + ",ou=" + col + ",ou=" + settings.PARENT + ",o=" + settings.ORG;
            }

        }
    }
}
